package sunstar.com.xq.activity

import android.os.Bundle
import android.os.Handler
import android.support.design.widget.Snackbar
import android.view.animation.AnimationUtils
import com.gyf.barlibrary.ImmersionBar
import kotlinx.android.synthetic.main.activity_login.*
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.startActivity
import sunstar.com.xq.R
import sunstar.com.xq.presenter.CheckLoginPresenter
import sunstar.com.xq.presenter.LoginPresenter
import sunstar.com.xq.shortcut.ShortCutManager
import sunstar.com.xq.view.LoginView

class LoginActivity : BaseActivity(), AnkoLogger, LoginView {

    override fun setBaseView(): Int = R.layout.activity_login

    override fun setTitleText(): String = ""

    override fun showTitle(): Boolean = false
    private var checkLoginPresenter: LoginPresenter?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar!!.hide()
        setContentView(R.layout.activity_login)
        checkLoginPresenter = LoginPresenter(this)
        ImmersionBar.with(this).init()
        setView()
    }

    private fun setView() {
        //开启动画
        Handler().postDelayed(
                Runnable {
                    main_bag.startAnimation(
                            AnimationUtils.loadAnimation(this@LoginActivity, R.anim.translate_anim)
                    )}
                ,200)
        ShortCutManager.initShortCut(this@LoginActivity)
        start_regist.setOnClickListener {
            startActivity<RegistActivity>()
        }
       login_login.setOnClickListener {
            if(checkLoginPresenter!!.check(login_username.text.toString(), login_password.text.toString()))
            { dialoUtil!!.show()
                checkLoginPresenter!!.login(this,login_username.text.toString(), login_password.text.toString())}
        }
        qq_login.setOnClickListener {
            Snackbar.make(start_regist,"开发中",2000).show()
        }
       wechat_login.setOnClickListener {
            Snackbar.make(start_regist,"开发中",2000).show()
        }
        weibo_login.setOnClickListener {
            Snackbar.make(start_regist,"开发中",2000).show()
        }
    }


    override fun onDestroy() {
        super.onDestroy()
        ImmersionBar.with(this).destroy()
    }

    override fun loginComplete() {
        dialoUtil!!.dismiss()
        finish()
    }

    override fun loginError(message: String) {
        Snackbar.make(start_regist,"1231234",2000).show()
    }
    override fun registStart() {
        startActivity<RegistActivity>()
    }

    override fun upDataPassword() {
    }

}
